package com.googlecode.scup.grammar.grammarspart;

public class Symbol {
	private String name;
	private boolean terminal;

	public Symbol (String name, boolean terminal) {
		this.name = name;
		this.terminal = terminal;
	}

	public Symbol (String name) {
		this(name, true);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setTerminal(boolean terminal) {
		this.terminal = terminal;
	}

	public boolean isTerminal() {
		return terminal;
	}

	public boolean equals(Object obj) {

		if (! (obj instanceof Symbol)) {
			return false;
		}

		Symbol s = (Symbol) obj;
		return name.equals(s.name) && (terminal == s.terminal);
	}

	public boolean equalsByName(Symbol s) {
		return name.equals(s.name);
	}

	public String toString() {
		return (terminal ? "Terminal" : "Nonterminal") + ": " + name.toString();
	}

	public int hashCode() {
		return name != null ? name.hashCode() : 0;
	}
}